<?php
     if(isset($_GET['secao'])){
                    session_start();
                    if(strcmp(session_id(),$_GET['secao'])==1){
                        header('Location: Login.php');
                    }
           echo "<html>";
                echo    "<head>";
                   echo "<title></title>";
                    echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">";
                    echo "<Link rel=\"stylesheet\" href=\"Forms.css\" type=\"text/css\"/>";
                echo "</head>";

                   
                        if(isset ($_GET['act']) && strcasecmp($_GET['act'],"alt")==0){
                            include_once 'Conexao.php';
                            $bd = new Conexao();
                            $bd->conectar();
                            $chave = $_GET['id'];
                            $obj=$bd->selectMedicamento($chave,2);
                            $info = mysql_fetch_array($obj);
                            $act = "altProduto";
                            $_SESSION["idImagem"]=$info['idImagem'];
                       }else
                           $act = "cadProduto";
                   

               echo "<form name=\"form1\" action=\"Inserts.php?act="; echo $act; echo "&id="; if(isset($_GET['id'])){ echo $_GET['id'];}else echo null; echo "\"   method=\"POST\"  enctype=\"multipart/form-data\">";
                    echo "<table><caption>Dados do produto</caption>";
                        echo "<tr/>";
                            echo "<td/>*Nome:";
                            echo "<td/><input type=\"text\" name=\"nome\" value=\""; if(isset($info['medicamento']))echo $info['medicamento']; echo"\">";
                        echo "<tr/>";
                            echo "<td/>*Preço normal:";
                            echo "<td/><input type=\"text\" name=\"precoNormal\" value="; if(isset($info['preco']))echo $info['preco']; echo ">";
                        echo "<tr/>";
                            echo "<td/>Quantidade:";
                            echo "<td/><input type =\"text\" name=\"quantidade\" value="; if(isset($info['quantidade']))echo $info['quantidade']; echo">";
                        echo "<tr/>";
                            echo "<td/>*Preco em oferta:";
                            echo "<td/><input type =\"text\" name=\"preco\" value="; if(isset($info['precoOferta']))echo $info['precoOferta'];echo">";
                        echo "<tr/>";
                            echo "<td/>Categoria:";
                            echo "<td/><select name=\"categoria\">";
                                    echo "<option "; if(isset($info['categoria']) && $info['categoria']==1)echo " selected "; echo "value=\"1\">Medicamento";
                                    echo "<option "; if(isset($info['categoria']) && $info['categoria']==2)echo " selected "; echo "value=\"2\">Cosmeticos";
                            echo "</select>";
                        echo "<tr/>";
                            echo "<td/>Está em oferta?";
                            echo "<td/><input type=\"radio\" name=\"oferta\" title=\"Sim\" value=\"1\"";
                                  if(isset($info['isOferta']) && $info['isOferta']==1)echo " checked=\"yes\" "; echo ">Sim";
                            echo "<BR/>";
                            echo "<input type=\"radio\" name=\"oferta\" title=\"Nao\" value=\"2\"";
                             if(isset($info['isOferta']) && $info['isOferta']==2) echo " checked=\"yes\" "; echo ">Não";
                        echo "<tr/>";
                            echo " <td/>Imagem para o medicamento:";
                            echo "<td/><input type = \"file\" name = \"arquivo\" value="; if(isset($info['url'])) echo "./Fotos/".$info['url'].">";
                        echo "<tr/>";
                            echo "<td align=\"right\">";
                            echo "<input type=\"submit\" name=\"enviar\" value=\"Confirmar\">";
                            echo "<td/>";
                            echo "<input type=\"reset\" name=\"limpar\" value=\"Limpar\">";
                    echo "</table>";
                echo "</form>";
            echo "</body>";
        echo "</html>";
     }else{
       header('Location: Login.php');
 }
 ?>
